
H5x.component("cover-uploader",[],function(opts){ 
    this.opts = opts;  
    this.container =  opts.container;
    this.use("render");
    this.use("emitter");
    this.init(); 

},{
    init:function(){ 
        var propname = this.opts.propname;
        var c = this.container;
        var self = this;


        this.render("tp-cover-uploader",{
            propname:propname
        });

        if(this.opts.value){
            c.find("input[name='"+propname+"']").val(this.opts.value);
            c.find("img.cover-image").attr("src",this.opts.value);
        }

        this.container.find(".up-cover-btn").bindUpload({
            url:"/common/upload",
            accept:"image/jpg,image/jpeg,image/png",
            params:{
                upload_dir:"covers"
            },
            oncomplate:function(data){
                //console.log(data);
                var d = JSON.parse(data);
                if(d.code > 0){
                    c.find("input[name='"+propname+"']").val(d.url);
                    c.find("img.cover-image").attr("src",d.url);
                }
            }
        });


        /*
        this.container.find(".add-class-btn").click(function(){
            var classname = prompt("请输入班级名称！");
            $(this).before('<span class="class-label">'
                +classname+'<span aria-hidden="true" class="label-close">&times;</span></span>');
        });

        this.container.on("click",".label-close",function(){
            $(this).parent().remove();
        })
        */
    }
});